package com.ruihu.admin.module.business.tasknode.domain.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruihu.admin.common.domain.BaseEntity;
import java.util.Date;
import java.util.List;
import java.util.Objects;

import com.ruihu.admin.common.mybatis.StringToLongListHandler;
import com.ruihu.admin.module.business.tasknode.domain.dto.SubTaskNodeInstAddDTO;
import com.ruihu.admin.module.business.tasknode.domain.dto.SubTaskNodeInstUpdateDTO;
import com.ruihu.admin.util.RequestTokenUtil;
import lombok.Data;

/**
 * [ 子任务环节实例表 ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2022-08-30 19:43:58
 * @since JDK1.8
 */
@Data
@TableName("t_sub_task_node_inst")
public class SubTaskNodeInstEntity extends BaseEntity {


    /**
     * 子任务ID
     */
    private Long subTaskId;

    /**
     * 任务环节实例ID
     */
    private Long taskNodeInstId;

    /**
     * 电芯类型编码
     */
    private String cellTypeCode;

    /**
     * 工厂编码
     */
    private String factoryCode;

    /**
     * 备注信息
     */
    private String remark;

    /**
     * 操作 NORMAL:正常   SKIP:跳过
     */
    private String action;

    /**
     * 表单数据
     */
    private String formData;

    /**
     * 乐观锁
     */
    private Integer revision;

    /**
     * 完成时间
     */
    private Date completionTime;

    /**
     * 创建人
     */
    private Long createBy;

    /**
     * 更新人
     */
    private Long updateBy;


    public static SubTaskNodeInstEntity convertToSubTaskNodeInstEntity(SubTaskNodeInstAddDTO addDTO) {
        if (addDTO == null) {
            return null;
        }

        SubTaskNodeInstEntity subTaskNodeInstEntity = new SubTaskNodeInstEntity();
        subTaskNodeInstEntity.setSubTaskId(addDTO.getSubTaskId());
        subTaskNodeInstEntity.setTaskNodeInstId(addDTO.getTaskNodeInstId());
        subTaskNodeInstEntity.setCellTypeCode(addDTO.getCellTypeCode());
        subTaskNodeInstEntity.setFactoryCode(addDTO.getFactoryCode());
        subTaskNodeInstEntity.setRemark(addDTO.getRemark());
        subTaskNodeInstEntity.setAction(addDTO.getAction());
        subTaskNodeInstEntity.setFormData(addDTO.getFormData());
        return subTaskNodeInstEntity;
    }

    public static SubTaskNodeInstEntity convertToSubTaskNodeInstEntity(SubTaskNodeInstUpdateDTO updateDTO) {
        if (updateDTO == null) {
            return null;
        }
        SubTaskNodeInstEntity subTaskNodeInstEntity = new SubTaskNodeInstEntity();
        subTaskNodeInstEntity.setId(updateDTO.getId());
        subTaskNodeInstEntity.setSubTaskId(updateDTO.getSubTaskId());
        subTaskNodeInstEntity.setTaskNodeInstId(updateDTO.getTaskNodeInstId());
        subTaskNodeInstEntity.setCellTypeCode(updateDTO.getCellTypeCode());
        subTaskNodeInstEntity.setFactoryCode(updateDTO.getFactoryCode());
        subTaskNodeInstEntity.setRemark(updateDTO.getRemark());
        subTaskNodeInstEntity.setFormData(updateDTO.getFormData());
        subTaskNodeInstEntity.setAction(updateDTO.getAction());

        return subTaskNodeInstEntity;
    }

    public static SubTaskNodeInstEntity convertToSubTaskNodeInstEntity(SubTaskNodeInstEntity sourceEntity, SubTaskNodeInstUpdateDTO updateDTO) {
        if (updateDTO == null) {
            return null;
        }
        sourceEntity.setId(updateDTO.getId());
        sourceEntity.setSubTaskId(updateDTO.getSubTaskId());
        sourceEntity.setTaskNodeInstId(updateDTO.getTaskNodeInstId());
        sourceEntity.setCellTypeCode(updateDTO.getCellTypeCode());
        sourceEntity.setFactoryCode(updateDTO.getFactoryCode());
        sourceEntity.setRemark(updateDTO.getRemark());
        sourceEntity.setAction(updateDTO.getAction());
        sourceEntity.setFormData(updateDTO.getFormData());
        sourceEntity.setUpdateTime(new Date());
        sourceEntity.setUpdateBy(RequestTokenUtil.getRequestUser().getRequestUserId());

        return sourceEntity;
    }

    public static SubTaskNodeInstEntity copyIgnoreNullAndEmpty(SubTaskNodeInstEntity sourceEntity, SubTaskNodeInstEntity destEntity) {
        if (sourceEntity == null) {
            return destEntity;
        }
        if (Objects.nonNull(sourceEntity.getId()))
            destEntity.setId(sourceEntity.getId());
        if (Objects.nonNull(sourceEntity.getSubTaskId()))
            destEntity.setSubTaskId(sourceEntity.getSubTaskId());
        if (Objects.nonNull(sourceEntity.getTaskNodeInstId()))
            destEntity.setTaskNodeInstId(sourceEntity.getTaskNodeInstId());
        if (StrUtil.isNotEmpty(sourceEntity.getCellTypeCode()))
            destEntity.setCellTypeCode(sourceEntity.getCellTypeCode());
        if (StrUtil.isNotEmpty(sourceEntity.getFactoryCode()))
            destEntity.setFactoryCode(sourceEntity.getFactoryCode());
        if (StrUtil.isNotEmpty(sourceEntity.getRemark()))
            destEntity.setRemark(sourceEntity.getRemark());
        if (StrUtil.isNotEmpty(sourceEntity.getAction()))
            destEntity.setAction(sourceEntity.getAction());
        if (StrUtil.isNotEmpty(sourceEntity.getFormData()))
            destEntity.setFormData(sourceEntity.getFormData());
        if (Objects.nonNull(sourceEntity.getRevision()))
            destEntity.setRevision(sourceEntity.getRevision());
        if (Objects.nonNull(sourceEntity.getCompletionTime()))
            destEntity.setCompletionTime(sourceEntity.getCompletionTime());
        if (Objects.nonNull(sourceEntity.getCreateBy()))
            destEntity.setCreateBy(sourceEntity.getCreateBy());
        if (Objects.nonNull(sourceEntity.getUpdateBy()))
            destEntity.setUpdateBy(sourceEntity.getUpdateBy());
        if (Objects.nonNull(sourceEntity.getUpdateTime()))
            destEntity.setUpdateTime(sourceEntity.getUpdateTime());
        if (Objects.nonNull(sourceEntity.getCreateTime()))
            destEntity.setCreateTime(sourceEntity.getCreateTime());
        return destEntity;
    }
}
